<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ page import="com.deepai.dprsmgr.utils.ErrCode" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="../base_path.jsp" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-cache"/>
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="description" content="">

    <link rel="stylesheet" type="text/css" href="<%=basePath%>/lib/bootstrap/3.3.7/css/bootstrap.min.css"/>
    <link type="text/css" rel="stylesheet" href="<%=basePath%>/lib/bootstrap-select/css/bootstrap-select.min.css"/>
    <link rel="stylesheet" type="text/css" media="screen" href="<%=basePath%>/lib/jqgrid/5.2.1/css/ui.jqgrid-bootstrap.css"/>
    <link rel="stylesheet" type="text/css" media="screen" href="<%=basePath%>/lib/lobibox/css/lobibox.min.css"/>
    <link rel="stylesheet" type="text/css" media="screen" href="<%=basePath%>/css/mycss.css"/>

    <title>组织管理</title>
	    <style>
	        .header-right {
	            position: absolute;
	            bottom: 16px;
	            right: 0px;
	        }
	
	        .page-header {
	            position: relative;
	        }
	
	        .block-head {
	            position: relative;
	            line-height: 66px;
	            font-size: 15px;
	            color: #545b66;
	            height: 23px;
	            display: inline-block;
	        }
	
	        .head-search {
	            position: absolute;
	            top: 2px;
	            right: 2px;
	            width: 280px;
	            height: 36px;
	            border-radius: 5px;
	            border: 1px solid #bcbec5;
	        }
	
	        .head-search.empty_input input {
	            height: 34px;
	            width: 240px;
	            border: none;
	            border-radius: 5px;
	            padding-left: 10px;
	            color: #757b84;
	            font-size: 14px;
	            background: transparent;
	        }
	
	        .head-search input {
	            height: 34px;
	            width: 206px;
	            border: none;
	            border-radius: 5px;
	            padding-left: 10px;
	            color: #757b84;
	            font-size: 14px;
	            background: transparent;
	        }
	
	        .search-btn {
	            float: right;
	            width: 26px;
	            height: 34px;
	            padding: 8px;
	            cursor: pointer;
	            padding-left: 0px;
	        }
	
	        .clear-btn {
	            float: right;
	            width: 26px;
	            height: 34px;
	            padding: 8px;
	            cursor: pointer;
	            padding-left: 0px;
	        }
	
	        .empty_input .clear-btn {
	            display: none;
	        }
	    </style>
	
</head>
<body>
<div class="navbar-fixed-top">
    <div class="breadcrumb">
        <span>账户管理</span>/
        <span class="active">组织管理</span>
        <span class="pull-right" title="刷新">
            <div class="btn-refresh" onclick="location.replace(location.href);">
            	<img src="<%=basePath%>/images/refresh.png" >
            </div>
        </span>
    </div>
</div>
<div class="container-fluid">
	<div class="container-fluid-main">
    <div class="page-header">
        <h3>组织管理</h3>
		<div class="header-right">
		    <button class="btn btn-primary" id="btn_create_org">创建组织</button>
		</div>
    </div>

    <div class="panel panel-default panel-default-sample">
        <div class="panel-body">
            <div>
                <form class="form-horizontal" id="from_select_item">
                    <div class="form-group">
                        <div class="col-sm-5">
                            <label class="control-label col-sm-3" for="txt_org_name">组织名称</label>
                            <div class="col-sm-9">
                               <!-- <shiro:hasAnyRoles name="role_super_admin,role_admin">
                                    <input type="text" class="form-control input-sm" id="txt_org_name" name="txt_org_name">
                                </shiro:hasAnyRoles>
                                <shiro:hasAnyRoles name="dep_leader,quality_specialist,analysis_specialist,call_specialist">
                                    <input type="text" class="form-control input-sm" id="txt_org_name" name="txt_org_name" disabled   value="">
                                </shiro:hasAnyRoles> -->


								 <select class="form-control input-sm" id="txt_org_name" name="txt_org_name"
								        data-live-search="true">
									<option value="0" selected>全部</option>
								    <c:forEach var="item" items="${orgList}">
								        <option value="${item.id}">${item.orgName}</option>
								    </c:forEach>
								</select>	
                            </div>
                        </div>
                        <div class="col-sm-5">
                            <label class="control-label col-sm-3" for="select_org_status">组织状态</label>
                            <div class="col-sm-9">
                                <select class="form-control input-sm" id="select_org_status">
                                    <option value="0" selected>请选择组织状态</option>
                                    <option value="1">启用</option>
                                    <option value="2">停用</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-2">
                            <button  class="btn btn-primary btn-sm sm-right-margin" id="btn_query">查询</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <table id="OrgJQGrid"></table>
    <div style="height: 40px" id="OrgJQGridPager"></div>
	</div>
</div>

<!-- 模态框（Modal） -->
    <div class="modal fade" id="modal_create_org" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
         aria-hidden="true">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">

            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
<!-- 模态框（Modal） -->
<div class="modal fade" id="modal_modify_org" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">修改组织信息</h4>
            </div>
            <div class="modal-body">
                <div class="container-fluid container-fluid-w" style="background: #FFF;width: 90%;margin-top: 20px;">
                    <form id="form_org_modify" class="form-horizontal" style="padding: 20px;">
                <div class="form-group">
                    <label  class="col-md-3 control-label">
                        <label class="text-danger" style="margin-right: 5px"></label>组织名称：</label>
                    <div class="col-md-8">
                        <p style="margin: 7px auto 0;color: #333;" id="diaorgname">组织名称</p>
                    </div>
                </div>
                <div class="form-group">
                    <label for="describe" class="col-md-3 control-label">
                        <label class="text-danger" style="margin-right: 5px"></label>描述：</label>
                    <div class="col-md-8">
                        <textarea  onkeyup="value=value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\ ,，。._]/g,'')"  type="text" class="form-control input-sm" id="describe"  name="describe" rows="3" maxlength="80"></textarea>
                        <span class="help-block"></span>
                    </div>
                </div>
                <div class="form-group">
                    <label for="txt_business_template" class="col-md-3 control-label">
                        <label class="text-danger" style="margin-right: 5px">*</label>业务模板：</label>
                    <div class="col-md-8">
                        <select id="txt_business_template" class="selectpicker form-control input-sm" multiple data-live-search="true"
                                name="txt_business_template" data-live-search-placeholder="Search" data-actions-box="true">
                            <c:forEach var="item" items="${allTemplateList}">
                                <option value="${item.id}">${item.templateName}</option>
                            </c:forEach>
                        </select>
                        <span class="help-block"></span>
                    </div>
                </div>
                <%--<div class="form-group">--%>
                    <%--<label for="txt_explicit_number" class="col-md-3 control-label">--%>
                        <%--<label class="text-danger" style="margin-right: 5px">*</label>外显号码：</label>--%>
                    <%--<div class="col-md-8">--%>
                        <%--<select id="txt_explicit_number" class="selectpicker form-control input-sm" multiple data-live-search="true"--%>
                                <%--name="txt_explicit_number" data-live-search-placeholder="Search" data-actions-box="true">--%>
                            <%--<c:forEach var="item" items="${allDisplayInfoList}">--%>
                                <%--<option value="${item.id}">${item.displayName}</option>--%>
                            <%--</c:forEach>--%>
                        <%--</select>--%>
                        <%--<span class="help-block"></span>--%>
                    <%--</div>--%>
                <%--</div>--%>
                <%--<div class="form-group">--%>
                    <%--<label for="txt_maximum_number" class="col-md-3 control-label">--%>
                        <%--<label class="text-danger" style="margin-right: 5px">*</label>最大并发数：</label>--%>
                    <%--<div class="col-md-8">--%>
                        <%--<input type="text" class="form-control input-sm" id="txt_maximum_number" name="txt_maximum_number" onkeyup="value=value.replace(/[^\d]/g,'')">--%>
                        <%--<span class="help-block"></span>--%>
                    <%--</div>--%>
                <%--</div>--%>
                <%--<div class="form-group">--%>
                    <%--<div class="col-sm-offset-3 col-sm-8">--%>
                        <%--<p style="line-height: 30px;background-color: #ccc;text-align: center;">剩余可分配并发数 <span id="maxNumber"></span></p>--%>
                    <%--</div>--%>
                <%--</div>--%>
                <div class="form-group text-c">

                        <button type="submit" class="btn btn-primary btn-sm">修改</button>

                </div>
            </form>
                </div>
            </div>
        </div>
    </div><!-- /.modal-content -->
</div><!-- /.modal -->

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="<%=basePath%>/lib/jquery/1.11.0/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/bootstrap/3.3.7/js/bootstrap.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/bootstrap-select/js/bootstrap-select.min.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/bootstrap-select/js/i18n/defaults-zh_CN.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/jquery.validation/1.14.0/jquery.validate_1.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/bootbox/bootbox.min.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/jqgrid/5.2.1/js/i18n/grid.locale-cn.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/jqgrid/5.2.1/js/jquery.jqGrid.min.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/lobibox/js/lobibox.min.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/lobibox/js/messageboxes.min.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/lobibox/js/notifications.min.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/common.js"></script>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="<%=basePath%>/js/common.js"></script>

<script type="text/javascript">
    var CallInfoJQGriddata = [];
    var fmp=null;
    $(function () {
		$("#txt_org_name").selectpicker();
        $.jgrid.defaults.responsive = true;
        $.jgrid.defaults.styleUI = "Bootstrap";
        $("#OrgJQGrid").jqGrid({
            height: 434,
            autowidth: true,
            shrinkToFit: true, /*  autoScroll: false, *//*forceFit: true, */
            colNames: ["主键", "组织名称", "组织状态", "创建时间", "部门组长(已用/剩余)",
                "业务专员", "模板","备注", "操作"],
            colModel: [
                {name: "org_id", index: "org_id", key: true, hidden: true},
                {name: "org_name", index: "org_name", align: "left", editable: true},
                {name: "status", index: "status", autowidth: true, align: "left"},
                {name: "create_time", index: "create_time", autowidth: true, align: "left"},
//                {name: "max_call_number", index: "max_call_number", autowidth: true, align: "left"},
                {name: "leader_count", index: "leader_count", autowidth: true, align: "left"},
//                {name: "quality_professionals_count", index: "quality_professionals_count", autowidth: true, align: "left"},
//                {name: "analysis_professionals_count", index: "analysis_professionals_count", autowidth: true, align: "left"},
                {name: "call_professionals_count", index: "call_professionals_count", autowidth: true, align: "left"},
                {name: "templateIds", index: "templateIds", hidden: true},
                {name: "comment", index: "comment", hidden: true},
                // {name: "edit", index: "result", autowidth: true, align: "left",hidden:(sessionStorage.getItem("hasPower")-0>2?true:false)}
				{name: "edit", index: "result", autowidth: true, align: "left",hidden: function() {
					<shiro:hasPermission name="xiugaizuzhixinxi">
					return false
					</shiro:hasPermission>
					return true
				}()}
			],
            page: 1,
            pager: "#OrgJQGridPager",
            viewrecords: true,
            hidegrid: false,
            multiselect: false,
            url: "<%=basePath %>/account/fetchOrgListForJQGrid.do",
            datatype: 'json',
            postData: getFilterData(),
            rownumbers: true,
            rowNum: 30,
            rowList: [15, 30, 50],
            jsonReader: {
                root: "dataList", page: "currPage", total: "totalPages",          //   很重要 定义了 后台分页参数的名字。
                records: "totalCount", repeatitems: false, id: "org_id"
            },
            loadComplete: function (data) {
                // 自动调整高度
                var resCount = data.records;
                CallInfoJQGriddata = data;
                var tableHeight = resCount * 30 + 40;
                $("#gbox_OrgJQGrid .ui-jqgrid-bdiv").css(
                    "cssText",
                    "height: " + tableHeight + "px!important;");
            },
            gridComplete: function () {         // 数据加载完成后 添加 采购按钮
                $("#OrgJQGrid").jqGrid('setLabel', 'rn', '序号', {'text-align': 'center', 'font-size': '12px'}, '');
                var ids = jQuery("#OrgJQGrid").jqGrid('getDataIDs');

                for (var i = 0; i < ids.length; i++) {
                    var id = ids[i];
                    var rowData = jQuery("#OrgJQGrid").jqGrid('getRowData', id);
                    // 调整显示样式
                    var htmlContent = rowData.admin_count + "/${maxGeneralAdminCount}";
                    var btncon="启用";
                    jQuery("#OrgJQGrid").jqGrid('setRowData', ids[i], {admin_count: htmlContent});
                    htmlContent = rowData.leader_count + "/${maxTeamLeaderCount}";
                    jQuery("#OrgJQGrid").jqGrid('setRowData', ids[i], {leader_count: htmlContent});
                    htmlContent = rowData.quality_professionals_count + "/${maxProfessionalsCount}";
                    jQuery("#OrgJQGrid").jqGrid('setRowData', ids[i], {quality_professionals_count: htmlContent});
                    htmlContent = rowData.analysis_professionals_count + "/${maxProfessionalsCount}";
                    jQuery("#OrgJQGrid").jqGrid('setRowData', ids[i], {analysis_professionals_count: htmlContent});
                    htmlContent = rowData.call_professionals_count + "/${maxProfessionalsCount}";
                    jQuery("#OrgJQGrid").jqGrid('setRowData', ids[i], {call_professionals_count: htmlContent});
					var editBtn = "<img src='<%=basePath%>/images/table/edit.png' alt='修改' style='cursor: pointer;margin-right:5px' onclick='editOrganize(this, " + id + ")'>"
                    if (rowData.status == "1") {
                        btncon="停用";
                        htmlContent = "<span class='label label-success'>启用</span>";
						editBtn += "<img src='<%=basePath%>/images/table/off.png' alt='停用' style='cursor: pointer;' onclick='stopOrganize(this, " + id + ")'>"
                    } else if (rowData.status == "2") {
						editBtn += "<img src='<%=basePath%>/images/table/on.png' alt='启用' style='cursor: pointer;' onclick='stopOrganize(this, " + id + ")'>"
                        htmlContent = "<span class='label label-info'>停用</span>";
                    }
                    jQuery("#OrgJQGrid").jqGrid('setRowData', ids[i], {status: htmlContent});
                    jQuery("#OrgJQGrid").jqGrid('setRowData', ids[i], {edit: editBtn});
                }
            }
        });


        $("#select_business_id").change(function () {
            fetchTaskInfo(getTaskFilterParamsStr());
        });

        $("#btn_query").click(function () {
            refreshJQGrid();
            return false;
        });
//        $("#updateOrganize").on("click", editOrganize);

        $("#txt_business_template").prop("disabled", false);
        $("#txt_business_template").selectpicker();
//        $("#txt_explicit_number").prop("disabled", false);
//        $("#txt_explicit_number").selectpicker();

        $('.selectpicker').on('hide.bs.select',function(e){
            $(this).focusout();
            if($(this).val() ==  null){
                $(this).addClass("has-error").siblings(".btn").addClass("redBorder");
            }else{
                $(this).removeClass("has-error").siblings(".btn").removeClass("redBorder");
            }
        });
        $("#form_org_modify").submit(function (event) {
            if($("#form_org_modify").valid()){
                var formData = new FormData(this);
                formData.append("orgId", $("#diaorgname").attr("orgId"));
                formData.append("comment", $.trim($("#describe").val().trim()));
                formData.append("templateIds",  $("#txt_business_template").val());
//                formData.append("displayIds", $("#txt_explicit_number").val());
//                formData.append("maxCallCount", $.trim($("#txt_maximum_number").val()));
                $.ajax({
                    url: '<%=basePath%>/account/orgUpdate.do',
                    type: 'POST',
                    data: formData,
                    async: false,
                    // 这两个参数需要被定义，否则报错
                    contentType: false,
                    processData: false,
                    traditional: true,
                    success: function (data) {
                        if(data["errorCode"] === "15001") {
                            myNotify("error", "", "修改的业务当中尚有未完成任务");
                        }else if(data["errorCode"] === "15003"){
                            myNotify("error", "", "修改的外显号码中尚有未完成任务");
                        }else if(data["errorCode"] === "15005"){
                            myNotify("error", "", "修改的业务当中尚有未停用的业务");
                        }else if(data["errorCode"] === "0"){
                            myNotify("success", "", "修改成功");
                        }else{
                            myNotify("error", "", "修改组织提交过程中发生错误，请联系管理员---！");
                        }
                        //关闭这个页面 给当前页面填充数据
                        $('#modal_modify_org').modal('hide');
                    },
                    error: function () {
                            myNotify("error", "", "修改组织提交过程中发生错误，请联系管理员！");
                    }
                });
            }else{
                    myNotify("error", "", "请更正错误后在进行提交");
            }
            return false;
        })
		
		$("#btn_create_org").click(function () {
			 $("#modal_create_org").modal({
			    backdrop: false,
			    keyboard: false,
			    remote: '<%=basePath %>/account/showOrgCreatePage.do'
			});
		});

		$("#modal_create_org").on("hidden.bs.modal", function() {
		    $(this).removeData("bs.modal");
		    $(this).find(".modal-content").children().remove();
            location.replace(location.href);
		});

        $("#modal_modify_org").on("hidden.bs.modal", function() {
//            $(this).removeData("bs.modal");
//            $(this).find(".modal-content").children().remove();
            location.replace(location.href);
        });
    })

    /******************************方法声明**********************************/
    /**
     * 刷新表格数据
     */
    function refreshJQGrid(mpage) {
        mpage=$.isNumeric(mpage)?mpage:1;
        $("#OrgJQGrid").jqGrid("setGridParam", {
            url: "<%=basePath%>/account/fetchOrgListForJQGrid.do",
            mtype: 'POST',
            datatype: "json",
            page: mpage,
            postData: getFilterData()
        }).trigger("reloadGrid");
    }

    function getFilterData() {
        var postData = {};
        postData.org_id =$.trim($("#txt_org_name").val());
        postData.status = $("#select_org_status").val();
        return postData;
    }

    function stopOrganize($this,id) {
        if($($this).attr('alt')== "启用"){
            businessEnable($this,id)
        }else{
            businessDisable($this,id)
        }
    }

    function businessDisable(obj, id) {
        bootbox.confirm({
            message: "停止后该组织下的人员及业务均无法使用，是否继续？",
            buttons: {
                confirm: {
                    label: '确认',
                    className: 'btn-success'
                },
                cancel: {
                    label: '取消',
                    className: 'btn-danger'
                }
            },
            callback: function (result) {
                if (result) {
                    var command = "disable";
                    $.ajax({
                        url: "<%=basePath%>/account/checkRunningTaskByOrgId.do",
                        type: "post",
                        async: true,
                        data: "orgId=" + id + "&command=" + command,
                        dataType: "json",
                        success: function (data) {
                            if (data["errorCode"] == "0") {
                                // myNotify("success", "", data["msg"]);
                                orgDisable(obj, id, command);
                            } else if (data["errorCode"] == "15001"){
                                bootbox.confirm({
                                    message: "任务正在外呼，停用此组织任务将终止执行，是否继续？",
                                    buttons: {
                                        confirm: {
                                            label: '确认',
                                            className: 'btn-success'
                                        },
                                        cancel: {
                                            label: '取消',
                                            className: 'btn-danger'
                                        }
                                    },
                                    callback: function (result) {
                                        if (result) {
                                            var command = "disable";
                                            orgDisable(obj, id, command);
                                        }
                                    }
                                });
                            }
                        },
                        error: function (data) {
                            myNotify("error", "", "操作请求发送过程中发生错误，请尽快联系管理员！");
                        }
                    });
                    
                }
            }
        });

    }

    function businessDisableNo() {
        bootbox.confirm({
            message: "当前组织存在执行中任务，或待执行中任务，无法停用该组织，请核实任务完成后，在停用当前组织",
            buttons: {
                confirm: {
                    label: '确认',
                    className: 'btn-success'
                }
            }
        });
    }

    function businessEnable(obj, id) {
        $.ajax({
            url: "<%=basePath%>/account/getRemainRobotCount.do",
            type: "post",
            async: true,
            dataType: "json",
            success: function (data) {
                var mynum=data.result;
                $.each(CallInfoJQGriddata.dataList, function (index, item) {
                    if (item.org_id == id) {
                            if(parseInt(item.max_call_number) > parseInt(mynum)){
                                myNotify("error", "", "当前最大并发数大于系统可用并发数，请修改后再启用！");
                            }else{
                                bootbox.confirm({
                                    message: "启用后该组织下的人员及业务均可使用，是否继续？",
                                    buttons: {
                                        confirm: {
                                            label: '确认',
                                            className: 'btn-success'
                                        },
                                        cancel: {
                                            label: '取消',
                                            className: 'btn-danger'
                                        }
                                    },
                                    callback: function (result) {
                                        if (result) {
                                            var command = "enable";
                                            orgEnable(obj, id, command);
                                        }
                                    }
                                });
                            }
                        return false;
                    }
                })
            },
            error: function (data) {
                myNotify("error", "", "最大并发数请求错误，请尽快联系管理员！");
            }
        });

    }

    function orgEnable(obj, id, command) {
        $.ajax({
            url: "<%=basePath%>/account/orgEnable.do",
            type: "post",
            async: true,
            data: "orgId=" + id,
            dataType: "json",
            success: function (data) {
                if (data["errorCode"] === "0") {
                        myNotify("success", "", "操作成功");
                    refreshJQGrid( $('#OrgJQGrid').jqGrid('getGridParam','page'));
                } else {
                        myNotify("error", "", "操作失败");
                }
            },
            error: function (data) {
                    myNotify("error", "", "操作请求发送过程中发生错误，请尽快联系管理员！");
            }
        });
    }


    function orgDisable(obj, id, command) {
        $.ajax({
            url: "<%=basePath%>/account/orgDisable.do",
            type: "post",
            async: true,
            data: "orgId=" + id,
            dataType: "json",
            success: function (data) {
                if (data["errorCode"] === "0") {
                        myNotify("success", "", "操作成功");
                    refreshJQGrid( $('#OrgJQGrid').jqGrid('getGridParam','page'));
                }else if(data["errorCode"] === "15001"){
                        myNotify("error", "", "请先确保所有任务已完成");
                } else {
                        myNotify("error", "", "操作失败");
                }
            },
            error: function (data) {
                    myNotify("error", "", "操作请求发送过程中发生错误，请尽快联系管理员！");
            }
        });
    }


    function getChecked() {
        var tasks = "";
        $("#ck_tasks").find("input").each(function () {
            if (tasks != "" && $(this).prop("checked")) {
                tasks += ","
            }
            if ($(this).prop("checked")) {
                tasks += $(this).attr("value").trim();
            }
        });
        return tasks;
    }

    function editOrganize($this,id) {
        //CallInfoJQGriddata
        $("#form_org_modify")[0].reset();
        $("#diaorgname,#maxNumber").html("")
        $('#txt_business_template').selectpicker('deselectAll')
        var selData = $("#OrgJQGrid").jqGrid('getRowData', id);
        $("#diaorgname").html(selData.org_name).attr("orgId", selData.org_id);
        $('#describe').val(selData.comment)
        $('#txt_business_template').selectpicker('val', selData.templateIds.split("、"));
//        $('#txt_explicit_number').selectpicker('val', item.displayIds.split("、"));
        $("#modal_modify_org").modal({
            backdrop: false,
            keyboard: false
        });
//        vaildateform();
        <%--$.ajax({--%>
            <%--url: "<%=basePath%>/account/getRemainRobotCount.do",--%>
            <%--type: "post",--%>
            <%--async: true,--%>
            <%--dataType: "json",--%>
            <%--success: function (data) {--%>
                <%--var mynum=data.result;--%>
                <%--$.each(CallInfoJQGriddata.dataList, function (index, item) {--%>
                    <%--if (item.org_id == id) {--%>

                        <%--if(item.status == 2){--%>
                            <%--mynum=parseInt(mynum);--%>
                            <%--$("#txt_maximum_number").val(0);--%>
                        <%--}else{--%>
                            <%--mynum=parseInt(item.max_call_number)+parseInt(mynum);--%>
                            <%--$("#txt_maximum_number").val(item.max_call_number);--%>
                        <%--}--%>
                        <%--$("#maxNumber").html(mynum);--%>
                        <%--$("#diaorgname").html(item.org_name).attr("orgId", item.org_id);--%>
                        <%--$('#describe').val(item.comment)--%>
                        <%--$('#txt_business_template').selectpicker('val', item.templateIds.split("、"));--%>
                        <%--$('#txt_explicit_number').selectpicker('val', item.displayIds.split("、"));--%>
                        <%--vaildateform(mynum)--%>
                        <%--return false;--%>
                    <%--}--%>
                <%--})--%>
                <%--$("#modal_modify_org").modal({--%>
                    <%--backdrop: false,--%>
                    <%--keyboard: false--%>
                <%--});--%>
            <%--},--%>
            <%--error: function (data) {--%>
                    <%--myNotify("error", "", "最大并发数请求错误，请尽快联系管理员！");--%>
            <%--}--%>
        <%--});--%>

    }


    function vaildateform(maxNumForValidate) {
        if (fmp != null) {
            fmp.destroy();
            fmp = null;
        }

        fmp =    $("#form_org_modify").validate({
            errorPlacement: function(error, element) {
                $( element )
                    .closest("div.form-group")
                    .find("span.help-block")
                    .append( error );
            },
            errorElement: "p",
            rules: {
                describe:{
                    required: false,
                },
                txt_business_template: {
                    required: true
                },
                txt_explicit_number: {
                    required: true
                },
                txt_maximum_number:{
                    required: true,
                    isLtNum:maxNumForValidate//动态获取
                }
            },
            messages: {
                txt_business_template: {
                    required: "请选择业务模板"
                },
                txt_explicit_number: {
                    required: "请选择外显号码"
                },
                txt_maximum_number:{
                    required: "请输入最大并发数",
                    isLtNum:"输入最大并发数不能超过"+maxNumForValidate//动态获取
                }
            }
        });
        $("#form_org_modify").find(".error,.redBorder").removeClass("error redBorder");
        fmp.resetForm();
    }
</script>
</body>
</html>